<template>
  <div>
    <el-dialog title="系统消息" :visible.sync="dialogVisible" width="30%" :before-close="closeDialog">
      <el-form ref="ruleForm" :model="ruleForm" :rules="rules" label-width="100px">
        <el-form-item label="标题" prop="title">
          <el-input v-model="ruleForm.title" />
        </el-form-item>
        <el-form-item label="对象" prop="status">
          <el-select v-model="value" placeholder="请选择" @change="selected">
            <el-option label="用户" value="user" />
            <el-option label="业务员" value="clerk" />
            <el-option label="商铺" value="shop" />
          </el-select>
        </el-form-item>
        <el-form-item label="内容" prop="center">
          <Editor v-model="ruleForm.center" @catchData="handleCatchData" />
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="closeDialog">取 消</el-button>
        <el-button type="primary" @click="confirm('ruleForm')">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import Editor from '@/common/editor'
export default {
  components: {
    Editor
  },
  data() {
    return {
      dialogVisible: false,
      value: '',
      ruleForm: {
        title: '',
        status: '',
        center: ''
      },
      rules: {
        title: [
          { required: true, message: '请输入标题', trigger: 'blur' }
        ],
        status: [
          { required: true, message: '请选择活动区域', trigger: 'change' }
        ],
        center: [
          { required: true, message: '请选择内容', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    show() {
      this.dialogVisible = true
    },
    closeDialog() {
      this.dialogVisible = false
    },
    confirm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.$emit('confirm', this.ruleForm)
          this.dialogVisible = false
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    selected(val) {
      this.ruleForm.status = val
    },
    handleCatchData(content) {
      console.log(content)
      const text = /<p>(.*?)<\/p>/.exec(content)
      this.ruleForm.center = text[1]
    },
    clear() {
      this.ruleForm.title = ''
      this.ruleForm.status = ''
      this.ruleForm.center = ''
      this.value = ''
    }
  }
}
</script>
<style lang="scss" scoped>
@import "@/styles/el-button.scss";
.el-input /deep/ .el-input__inner{
  width: 365px !important;
}
.el-select /deep/ .el-input__inner{
  width: 365px !important;
}
.el-dialog__wrapper /deep/ .el-dialog {
  min-width: 1000px;
}
.el-form /deep/ .el-form-item__label {
  white-space: nowrap;
  color: rgba(102, 102, 102, 1);
  font-size: 14px;
  font-family: Roboto;
}
.el-form /deep/ .el-input__inner {
  width: 278px;
  height: 36px;
}
.el-form /deep/ .el-textarea__inner {
  width: 278px;
  height: 137px;
}
.dialog-footer {
  button {
    &:nth-child(1) {
      background-color: rgba(255, 255, 255, 1);
      color: rgba(16, 16, 16, 1);
      font-size: 14px;
      text-align: center;
      font-family: Roboto;
    }
  }
}
</style>
